<template>
	<view>
		<Header :isBack="true">
			<block slot="content">{{title}}</block>
		</Header>

		<!-- 占位 -->
		<!-- <view class="place"></view> -->

		<view class="order-title-box">
			<view class="order-title">
				<view class="order-title-item" :class="{ active : active1 }" @tap="version('-2')">
					<text>全部</text>
				</view>
				<view class="order-title-item" :class="{ active : active2 }" @tap="version('0')">
					<text>待审核</text>
				</view>
				<view class="order-title-item" :class="{ active : active3 }" @tap="version('1')">
					<text>已同意</text>
				</view>
				<view class="order-title-item" :class="{ active : active4 }" @tap="version('-1')">
					<text>已驳回</text>
				</view>
			</view>
		</view>

		<!-- 空白页 -->
		<empty v-if="isLoaded === false" :top="182"></empty>

		<view class="" v-show="isLoaded">
			<view class="list" v-if="jobData.length > 0">
				<view class="list-item" v-for="item in jobData" :key="item.id">
					<view class="img-wrapper">

						<view class="img-wrapper-header">
							<view class="img-wrapper-line1">
								<text>提现申请</text>
								<text>-{{item.money}}</text>
							</view>
							<view class="img-wrapper-line2">
								<text class="addtime">{{item.addtime}}</text>
								<text v-if="item.status == -1" style="color:#ff8a01">已驳回</text>
								<text v-if="item.status == 0" style="color:#f90101">审核中</text>
								<text v-if="item.status == 1" style="color:#1a76f3">已同意</text>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="empty" v-else>
				<image src="/static/images/zanwushuju.png" alt="" class="empty-img"></image>
			</view>
		</view>

		<!-- 底部菜单 -->
		<BottomTabbar :selected="3"></BottomTabbar>
	</view>

</template>

<script>
	import BottomTabbar from '@/components/bottom-tabbar/bottom-tabbar.vue';
	import empty from "@/components/empty";
	export default {
		data() {
			return {
				title: '提现记录',
				// menuTop: '196',

				loadingText: "正在加载...",
				defaultSelected: [],

				jobData: [],
				page: 1,
				isLoaded: false,

				active1: true,
				active2: false,
				active3: false,
				active4: false,

				status: -2,

				isShowMsg: true,
			}
		},

		components: {
			BottomTabbar,
			empty
		},

		// 页面生命周期，下拉刷新后触发
		onPullDownRefresh() {
			//判断是否登录
			let result = this.$api.isLogin();
			if (result === false) {
				return false;
			}
			this.loadData()

			// 停止下拉刷新
			setTimeout(function() {
				uni.stopPullDownRefresh()
			}, 600)
		},

		//下拉到底获取新的数据
		onReachBottom() {
			this.getNewJobs();
		},

		onLoad: function(option) {
			//判断是否登录
			let result = this.$api.isLogin();
			if (result === false) {
				return false;
			}

			switch (option.status) {
				case '-2':
					this.active1 = true;
					this.active2 = false;
					this.active3 = false;
					this.active4 = false;
					break;
				case '0':
					this.active1 = false;
					this.active2 = true;
					this.active3 = false;
					this.active4 = false;
					break;
				case '1':
					this.active1 = false;
					this.active2 = false;
					this.active3 = true;
					this.active4 = false;
					break;
				case '-1':
					this.active1 = false;
					this.active2 = false;
					this.active3 = false;
					this.active4 = true;
					break;
			}

			uni.showLoading({
				title: '加载中...'
			});
			// this.title = option.title;
			this.loadData();
			setTimeout(() => {
				this.isLoaded = true;
				uni.hideLoading();
			}, 600)

			uni.$on('updateWithdrawlRecord', () => {
				this.loadData();
			})
		},
		methods: {
			async loadData() {
				this.page = 1;
				this.getNewJobs();
			},
			async version(id) {
				this.status = id;
				switch (id) {
					case '-2':
						this.active1 = true;
						this.active2 = false;
						this.active3 = false;
						this.active4 = false;
						break;
					case '0':
						this.active1 = false;
						this.active2 = true;
						this.active3 = false;
						this.active4 = false;
						break;
					case '1':
						this.active1 = false;
						this.active2 = false;
						this.active3 = true;
						this.active4 = false;
						break;
					case '-1':
						this.active1 = false;
						this.active2 = false;
						this.active3 = false;
						this.active4 = true;
						break;
				}

				uni.showLoading({
					title: '加载中...'
				});
				this.loadData();
				setTimeout(() => {
					this.isLoaded = true;
					uni.hideLoading();
				}, 600)
			},

			//职位列表
			async getNewJobs() {
				let token = uni.getStorageSync('token');
				let dataObj = {
					page: this.page,
					token: token,
					status: this.status
				}

				let jdata = await this.$myRequest({
					url: '/wdRecord',
					data: dataObj,
					methods: 'POST'
				})
				let ndata = jdata.data.data;

				if (this.page === 1) {
					this.jobData = ndata;
					if (ndata.length === 0) {
						if (this.isShowMsg == true) {
							this.$api.msg('亲！暂无数据！！！')
						}
					} else {
						this.page = this.page + 1;
					}
				} else {
					if (ndata.length === 0) {
						if (this.jobData.length === 0) {
							if (this.isShowMsg == true) {
								this.$api.msg('亲！暂无数据！！！')
							}
						} else {
							if (this.isShowMsg == true) {
								this.$api.msg('亲！已经到底了！！！')
							}
						}

					} else {
						this.jobData = [...this.jobData, ...ndata];
						this.page = this.page + 1;
					}
				}
			}
		}
	}
</script>

<style>
	page {
		background-color: #f7f7f7;
		font-size: $font-base;
	}
</style>

<style lang='scss' scoped>
	.order-title-box {
		position: fixed;
		
		// #ifdef APP-PLUS
		top: 160rpx;
		// #endif

		// #ifdef H5
		top: 100rpx;
		// #endif
		
		width: 100%;
		background-color: #ffffff;
		font-size: 30rpx;
		z-index: 100;

		.order-title {
			height: 78rpx;
			padding: 18rpx 42rpx 18rpx;
			font-size: 30rpx;
			display: flex;
			justify-content: space-between;

			.order-title-item {
				height: 42rpx;
			}
		}
	}

	.list {
		// #ifdef APP-PLUS
		padding: 253rpx 15rpx 135rpx;
		// #endif
		
		// #ifdef H5
		padding: 193rpx 15rpx 135rpx;
		// #endif

		.list-item {
			background-color: #fff;
			display: flex;
			flex-direction: column;
			align-items: center;
			height: 102rpx;
			border-radius: 10rpx;
			margin-bottom: 15rpx;

			.img-wrapper {
				width: 100%;
				height: 102rpx;
				position: relative;
				padding: 0 27rpx;
				border-bottom: 1px solid #f3f3f6;

				.img-wrapper-header {
					height: 102rpx;
					position: relative;
					line-height: 51rpx;

					.img-wrapper-line1,
					.img-wrapper-line2 {
						display: flex;
						justify-content: space-between;
					}

				}

			}
		}
	}

	.datajson {
		z-index: 2;
		position: fixed;
		left: 0;
		right: 0;
		bottom: 0;
		height: 250px;
		padding: 0 10px;
		background-color: rgba(255, 255, 255, .8);
		backdrop-filter: blur(15px);
		-webkit-backdrop-filter: blur(15px);
		font-size: 12px;

		.text {
			margin-top: 10px;
		}

		.item {
			width: 15px;
		}
	}

	.addtime {
		color: #cccccc;
		font-size: 26rpx;
	}



	.swiper {
		width: 100%;
		margin-top: 10upx;
		display: flex;
		justify-content: center;

		.swiper-box {
			width: 92%;
			height: 230rpx;

			overflow: hidden;
			border-radius: 15rpx;
			box-shadow: 0upx 8upx 25rpx rgba(0, 0, 0, 0.2);
			//兼容ios，微信小程序
			position: relative;
			z-index: 1;

			swiper {
				width: 100%;
				height: 230rpx;

				swiper-item {
					image {
						width: 100%;
						height: 230rpx;
					}
				}
			}

			.indicator {
				position: absolute;
				bottom: 20upx;
				left: 20upx;
				background-color: rgba(255, 255, 255, 0.4);
				width: 150upx;
				height: 5upx;
				border-radius: 3upx;
				overflow: hidden;
				display: flex;

				.dots {
					width: 0upx;
					background-color: rgba(255, 255, 255, 1);
					transition: all 0.3s ease-out;

					&.on {
						width: (100%/3);
					}
				}
			}
		}
	}

	.active {
		color: #f3431a !important;
		border-bottom: 1px solid #f3431a;
	}

	.empty {
		position: absolute;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
		
		.empty-img {
			width: 182rpx;
			height: 182rpx;
		}
	}
</style>
